<?php
session_start();

// Redirect to login page if not logged in
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
    header('Location: index.php');
    exit;
}

$username = $_SESSION['username'];
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            min-height: 100vh;
            background-color: #f4f4f4;
        }

        .sidebar {
            width: 250px;
            background-color: #333;
            color: #fff;
            padding: 20px;
            box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
        }

        .sidebar h2 {
            text-align: center;
            margin-bottom: 20px;
            font-size: 24px;
        }

        .sidebar ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar ul li {
            margin: 15px 0;
        }

        .sidebar ul li a {
            color: #fff;
            text-decoration: none;
            font-size: 18px;
            display: block;
            padding: 10px;
            border-radius: 4px;
            transition: background-color 0.3s;
        }

        .sidebar ul li a:hover {
            background-color: #444;
        }

        .main-content {
            flex: 1;
            padding: 20px;
            background-color: #fff;
            margin: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .main-content iframe {
            width: 100%;
            height: calc(100vh - 100px);
            border: none;
            border-radius: 8px;
        }

        .logout-link {
            display: block;
            text-align: center;
            margin-top: 20px;
            color: #fff;
            background-color: #dc3545;
            padding: 10px;
            border-radius: 4px;
            text-decoration: none;
            transition: background-color 0.3s;
        }

        .logout-link:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body>
    <!-- Sidebar -->
    <div class="sidebar">
        <h2>Dashboard</h2>
        <ul>
            <li><a href="#" onclick="loadPage('home.php')">Home</a></li>
            <li><a href="#" onclick="loadPage('profile.php')">Profile</a></li>
            <li><a href="#" onclick="loadPage('settings.php')">Settings</a></li>
        </ul>
        <a href="logout.php" class="logout-link">Logout</a>
    </div>

    <!-- Main Content -->
    <div class="main-content">
        <iframe id="content-frame" src="home.php"></iframe>
    </div>

    <script>
        // Function to load a page into the iframe
        function loadPage(page) {
            const iframe = document.getElementById('content-frame');
            iframe.src = page;
        }
    </script>
</body>
</html>